package kaist.sep521.lego.circlebicycle;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class GroupListParserHandler extends DefaultHandler {
	private String position = "";
	private ArrayList<String> pGroupList;

	public ArrayList<String> getParsedData() {
		return this.pGroupList;
	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		super.characters(ch, start, length);

		String str = new String(ch, start, length).trim();
		if (position.equals("group")) {
			pGroupList.add(str);
			position = "";
		}
	}

	@Override
	public void startDocument() throws SAXException {
		super.startDocument();
	}

	@Override
	public void endDocument() throws SAXException {
		super.endDocument();
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		super.startElement(uri, localName, qName, attributes);
		if (qName.equals("grouplist")) {
			pGroupList = new ArrayList<String>();
		} else if (qName.equals("group")) {
			position = "group";
		}
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		super.endElement(uri, localName, qName);
	}
}
